#include "NetCal.hpp"
#include "Protocol.hpp"
#include "TcpServer.hpp"
#include <memory>

void Usage(std::string proc)
{
    std::cerr << "Usage" << proc << " port" << std::endl;
}


// ./TcpServer 8080
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }

    //1.顶层
    std::unique_ptr<Cal> cal = std::make_unique<cal>(); 

    //2.协议层
    std::unique_ptr<Protocol> protocl = std::make_unique<Protocol>();//调用默认构造

    //服务器层
    //TcpServer 需要 port/service(sockptr client)
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(std::stoi(argv[1]),
        [&protocl](std::shared_ptr<Socket> &sock, InetAddr &client)
        {
            protocl->GetRequest(sock, client);
        });

    tsvr -> Start();


    return 0;
}
